package com.example.thirdhomework
import android.content.Intent
import android.widget.EditText
import android.widget.Button
import android.widget.TextView
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

const val FIRST_MSG ="FIRST_MSG"
const val SECOND_MSG ="SECOND_MSG"
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        enableEdgeToEdge()
        val first: Button = findViewById(R.id.first)
        val editText:EditText = findViewById(R.id.editText)
        val second:Button=findViewById(R.id.second)
        val third:Button=findViewById(R.id.third)
        val fourth:Button=findViewById(R.id.fourth)

        first.setOnClickListener {
            val intent = Intent(this,SecondActivity::class.java)
            intent.putExtra(FIRST_MSG,editText.text.toString())
            startActivity(intent)
        }

        second.setOnClickListener{
            val intent=Intent(this,ThirdActivity::class.java)
            startActivityForResult(intent,0)
        }

        third.setOnClickListener {
            val intent = Intent(this, FourthActivity::class.java)
            startActivityForResult(intent, 1000)
        }
        fourth.setOnClickListener {
            val intent = Intent(this,FifthActivity::class.java)
            startActivityForResult(intent, 1)
        }

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        val textView: TextView = findViewById(R.id.textView)
        if (requestCode==0){
            if(resultCode==1){
                textView.text=data?.getStringExtra(SECOND_MSG)
            }
        }
    }

}